/*
 * @Author: xiaosihan 
 * @Date: 2023-02-06 15:22:57 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-05-27 00:59:10
 */
import { AmbientLight, LinearSRGBColorSpace, PointLight, Vector3 } from "three";
import ThreeBase from "three-base";

import Indicator from "./component3d/Indicator/Indicator";
import homeRenderer from "./homeRender";

/**
 * @class 东南西北渲染器
 * @extends {ThreeBase}
 */
class IndicatorRenderer extends ThreeBase {

    constructor() {
        super();
    }

    //环境光
    ambientLight = (() => {
        const ambientLight = new AmbientLight("#ffffff", 5);
        this.scene.add(ambientLight);
        return ambientLight;
    })();

    //点光源1
    pointLight1 = (() => {
        const pointLight = new PointLight("#fff", 5, 100, 0);
        this.scene.add(pointLight);
        return pointLight;
    })();

    //点光源2
    pointLight2 = (() => {
        const pointLight = new PointLight("#fff", 5, 100, 0);
        this.scene.add(pointLight);
        return pointLight;
    })();


    // 东南西北指示器
    indicator = (() => {
        const indicator = new Indicator();
        this.scene.add(indicator);
        return indicator;
    })();


    init() {
        super.init();
        this.gridHelper.visible = false;
        this.axesHelper.visible = false;
        this.renderer.outputColorSpace = LinearSRGBColorSpace;
        this.resetLookAt({
            center: new Vector3(0, 0, 0),
            position: new Vector3(0, 120, 175)
        });

    }

    render() {
        this.perspectiveCamera.position.copy(homeRenderer.perspectiveCamera.position).sub(homeRenderer.controls.target).setLength(6);
        this.perspectiveCamera.lookAt(this.scene.position);
        this.pointLight1.position.copy(this.perspectiveCamera.position);
        this.pointLight2.position.copy(this.perspectiveCamera.position).multiply(new Vector3(-1, 1, -1));
        return super.render();
    }

}


const indicatorRenderer = window.indicatorRenderer = new IndicatorRenderer();

export default indicatorRenderer;